import java.sql.SQLOutput;
import java.util.*;

public class Test {
	public static void main(String[] args) {
		//选择排序
		int i,j;
		int arr[]={9,27,10,1,49};
		for( i=0;i<arr.length;i++) {
			int k=i;
			for(j=i+1;j<arr.length;j++) {
				if(arr[j]>arr[k]) {
					k=j;
				}
			}
			int temp=arr[i];
			arr[i]=arr[k];
			arr[k]=temp;
		}
		System.out.println(Arrays.toString(arr));
	}
	public static void main9(String[] args) {
		//二维数组的打印
		int [] [] numss={{1,2,3},{1,5},{4,5,6,7,}};
		for(int i=0;i<numss.length;i++) {
			int [] nums=numss[i];
			for(int j=0;j<nums.length;j++) {
				System.out.print(nums[j]+" ");
			}
			System.out.println();
		}
	}
	public static int  BinarySort(int []arr,int key) {
		int left=0;
		int right=arr.length-1;
		int mid=0;
		while(left<=right) {
			mid=(left+right)/2;
			if(arr[mid]==key) {
				return mid;
			} else if(arr[mid]>key) {
				right=mid-1;
			} else {
				left=mid+1;
			}
		}
		return -1;
	}
	//二分查找
	public static void main8(String[] args) {
		int [] arr=new int [] {1,2,3,4,5,6,7,8,9,10};
		//进行优化，并不是每次手动更改值，让他自动更改要找到值
		Random random=new Random();
		int len=10;
		while(len!=0) {
			int index=random.nextInt(arr.length);
			int key=arr[index];
			int index1=BinarySort(arr,key);
			System.out.println("找到的下标为"+index1+"下标对应值为"+arr[index1]);
			len--;
		}
	}
	//冒泡排序优化，排完一趟之后，再没有交换flg的值没有改变
	//说明数组的内容已经有序了，不需要再进行排序了。
	public static void main7(String[] args) {
		//冒泡排序，以及优化
		int [] arr=new int[] {2,1,3,4};
		for (int i = 0; i < arr.length; i++) {
			boolean flg = false;
			for (int j = 0; j < arr.length - 1 - i; j++) {
				if (arr[j] > arr[j + 1]) {
					int temp = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = temp;
					flg = true;
				}
			}
			if (flg == false) {
				break;
			}
		}
		System.out.println(Arrays.toString(arr));
	}
	public static void main6(String[] args) {
		//打印乘法表
		for(int i =9;i>=1;i--) {
			for(int j=1;j<=i;j++) {
				System.out.print(i+"*"+j+"="+i*j+"\t");
			}
			System.out.println();
		}
		for(int i=1;i<=10;i++) {
			for(int j =1;j<=10;j++) {
				if(i*j>50) {
					System.out.println("-------超过50--------");
					continue;
				}
				System.out.println(i+"*"+j+"="+j*i+"\t");
			}
		}
		outer:for(int i=1;i<=10;i++) {
			inner:for(int j =1;j<=10;j++) {
				if(i*j>50) {
					System.out.println("-------超过50--------");
					continue outer;
				}
				System.out.println(i+"*"+j+"="+j*i+"\t");
			}
		}
				 for (int i = 0; i < 10; i++) {
					System.out.print("\n");
					for (int j = 0; j < 10; j++) {
						if (j == 5) {
							continue ;
							//当没有任何的跳转指向的时候，continue的下面语句不执行，直接跳过判断条件的这句打印。
						}
						System.out.print(j + " ");
					}
			}
	}
	public static void main5(String[] args) {
		BinaryTree binaryTree=new BinaryTree();
		BinaryTree.TreeNode root=binaryTree.createTree();
		binaryTree.preOrderNor(root);
		System.out.println();
		binaryTree.preOrder(root);
		System.out.println("============");
		binaryTree.inOrder(root);
		System.out.println();
		binaryTree.inOrderNor(root);
		System.out.println("=========");
		binaryTree.postOrderNor(root);
	}
	public static void main4(String[] args) {
		BinaryTree binaryTree=new BinaryTree();
		BinaryTree.TreeNode root=binaryTree.createTree1();
		List<List<BinaryTree.TreeNode>> list=binaryTree.levelOrder1(root);
		System.out.println(list.size());
		System.out.println("================");
		int max=list.get(0).size();
		for(int i =0;i<list.size();i++) {
			if(list.get(i).size()>max) {
				max=list.get(i).size();
			}
		}
		System.out.println("二叉树的最大宽度为:"+ max);
		//求左视图和右视图
		for(int i = 0;i<list.size();i++) {
			char ch=list.get(i).get(0).val;
			System.out.print("左视图为:"+ch+" ");
		}
		System.out.println();
		for(int i = 0;i<list.size();i++) {
			int size=list.get(i).size();
			char ch=list.get(i).get(size-1).val;
			System.out.print("右视图为:"+ch+" ");
		}
	}
	public static void main3(String[] args) {
		BinaryTree binaryTree=new BinaryTree();
		BinaryTree.TreeNode root=binaryTree.createTree();
		binaryTree.levelOrder(root);
		System.out.println("==========");
		System.out.println(binaryTree.isCompleteTree(root));
		System.out.println("============");
	}
	public static void main2(String[] args) {
		Random random=new Random();
		int n1= random.nextInt(100);
		System.out.println(n1);
		BinaryTree root=new BinaryTree();
		BinaryTree.TreeNode ret=root.createTree();
//		root.preOrder(ret);
//		System.out.println();
//		System.out.println("========");
//		root.inOrder(ret);
//		System.out.println();
//		System.out.println("=========");
//		root.postOrder(ret);
//		System.out.println();
		System.out.println("节点的数量为："+root.size(ret));
		System.out.println("叶子节点的数量："+root.getLeafNodeCount(ret));
		System.out.println("k层的节点数量为:"+root.getKLevelNodeCount(ret,3));
		System.out.println("二叉树的高度为"+root.getHeight(ret));
		boolean flg=root.find(ret,'H');
		if(flg==true) {
			System.out.println("1111");
		}else {
			System.out.println("222222222");
		}
	}
	public static void main1(String[] args) {
		BinaryTree root=new BinaryTree();
		BinaryTree.TreeNode ret=root.createTree();
//		root.preOrder(ret);
//		System.out.println();
//		System.out.println("==========");
		System.out.println(root.preOrder1(ret));
		List<BinaryTree.TreeNode> listTree=root.preOrder1(ret);
		ListIterator<BinaryTree.TreeNode> it= listTree.listIterator();
		while(it.hasNext()) {
			System.out.print(it.next());
		}
		System.out.println();
	}
}

